<?php
namespace Core\Helper;

use Zend\Filter\StringTrim;
use Zend\Validator\EmailAddress;
use Zend\Validator\StringLength;
use Zend\Validator\ValidatorChain;

class AdminInputHelper{

    public static function filterDomainName($domainName)
    {
        $filter = new StringTrim();
        return $filter->filter($domainName);
    }

    public static function filterStringTrim($sample)
    {
        $filter = new StringTrim();
        return $filter->filter($sample);
    }


    /**
     * @param $domainName
     * @return ValidatorDto
     */
    public static function validateDomainName($domainName)
    {
        $validatorChain = new ValidatorChain();
        $stringLength = new StringLength(array('min' => 4));
        $stringLength->setMessage('Tên nhà hàng dài ít nhất 4 ký tự', StringLength::TOO_SHORT);
        $validatorChain->attach(
            $stringLength);

        if($validatorChain->isValid($domainName))
            return new ValidatorDto(true);
        else
            return new ValidatorDto(false,$validatorChain->getMessages());

    }

    /**
     * @param $sample
     * @return ValidatorDto
     */
    public static function validateStringLength($sample, $length)
    {
        $validatorChain = new ValidatorChain();
        $stringLength = new StringLength(array('min' => $length));
        $stringLength->setMessage('Chuỗi dài ít nhất '.$length.' ký tự', StringLength::TOO_SHORT);
        $validatorChain->attach(
            $stringLength);

        if($validatorChain->isValid($sample))
            return new ValidatorDto(true);
        else
            return new ValidatorDto(false,$validatorChain->getMessages());

    }

    /**
     * @param $sample
     * @return ValidatorDto
     */
    public static function validateEmail($sample)
    {
        $validatorChain = new ValidatorChain();
        $stringLength = new StringLength(array('min' => 5));
        $stringLength->setMessage('Email dài ít nhất 5 ký tự', StringLength::TOO_SHORT);
        $validatorChain->attach(
            $stringLength);
        $email = new EmailAddress(array());
        $email->setMessage('Email không đúng định dạng', EmailAddress::INVALID_FORMAT);
        $email->setMessage('Email không đúng định dạng', EmailAddress::INVALID);
        if($validatorChain->isValid($sample))
            return new ValidatorDto(true);
        else
            return new ValidatorDto(false,$validatorChain->getMessages());

    }


    /**
     * @param $passWord
     * @return ValidatorDto
     */
    public static function validatePassword($passWord)
    {
        $validatorChain = new ValidatorChain();
        $stringLength = new StringLength(array('min' => 6));
        $stringLength->setMessage('Password dài ít nhất 4 ký tự', StringLength::TOO_SHORT);
        $validatorChain->attach($stringLength);
        if($validatorChain->isValid($passWord))
            return new ValidatorDto(true);
        else
            return new ValidatorDto(false,$validatorChain->getMessages());
    }

}